<template>
	<view class="register">
		<Hearder :name="'注册'"></Hearder>
		<view class="content">
			<view class="itemList">
				<view>手机号</view>
				<input type="text" placeholder="请输入手机号" placeholder-style="color:#999" v-model="phone" />
			</view>
			<view class="itemList yzm">
				<view>验证码</view>
				<input type="text" placeholder="请输入验证码" placeholder-style="color:#999" v-model="ver_code" />
				<text class="getcode" @click="getCode">{{initcode}}</text>
			</view>
			<view class="itemList">
				<view>密码</view>
				<input type="password" placeholder="请输入密码" placeholder-style="color:#999" v-model="password"/>
			</view>
			<view class="itemList">
				<view>重复密码</view>
				<input type="password" placeholder="请重复输入密码" placeholder-style="color:#999" v-model="password_confirm"/>
			</view>
			<view class="itemList">
				<view>邀请码</view>
				<input type="text" placeholder="请输入邀请码（必填）" placeholder-style="color:#999" v-model="code"/>
			</view>	
			<view class="nextBtn" @click="$u.throttle(suresubmit, 1000)">确认注册</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				initcode:'发送',
				phone:'',
				code:'',
				password:'',
				password_confirm:'',
				invite_code:'',
				second:60,
				ver_code:''
			}
		},
		methods:{
			getCode(){
				var that=this
				if(this.initcode=='发送'){
					this.request('/v1/sms',{phone: this.phone,type:'register'},'GET').then(res => {
						if(res.data.code==1){
							 this.$tip(res.data.msg);
							 var interval = setInterval(() => {
							    --this.second
							    that.initcode=this.second+'s'
							 }, 1000)
							 setTimeout(() => {
							    clearInterval(interval)
							    this.initcode='发送'
								this.second=60
							 }, 60000)
						}else{
							this.$tip(res.data.msg);
						}
					})
				}
			},
			suresubmit(){
				this.request('/member/register',{
					phone:this.phone,
					code:this.code,
					password:this.password,
					password_confirm:this.password_confirm,
					invite_code:this.invite_code,
					ver_code:this.ver_code
				}).then(res => {
					if(res.data.code==1){
						this.$tip(res.data.msg)
						// uni.setStorageSync('TOKEN',res.data.data.token);
						// uni.switchTab({
						// 	url:'/pages/index/index'
						// })
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/login/login'
							})
						},500)
					}else{
						this.$tip(res.data.msg)
					}	
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.register{
		.content{
			padding: 0 4%;
			.itemList{
				display: flex;
				align-items: center;
				overflow: hidden;
				border-bottom: 1rpx solid $uni-background-color;
				height: 108rpx;
				>view{
					width: 28%;
				}
				input{
				  width: 72%;
				  height: 80%;
				  margin-top: 2rpx;
				}
				.getcode{
					width: 133rpx;
					height: 50rpx;
					text-align: right;
					line-height: 50rpx;
					color: $uni-item-color;
				}
			}
			.yzm input{
				width: 52%;
			}
			.nextBtn{
				width: 600rpx;
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				background: $uni-item-color;
				margin: 50rpx auto;
				color: #fff;
			}
		}
	}
</style>